package com.lj.back.manage.scaffold.common.annotation.valid;

import com.lj.back.manage.scaffold.common.constant.Constant;
import org.hibernate.validator.constraints.CompositionType;
import org.hibernate.validator.constraints.ConstraintComposition;

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 验证码校验注解
 * @author lv
 * @version 1.0.0
 */
@ConstraintComposition(CompositionType.AND)
@NotBlank(message = "{code.notnull}")
@Pattern(regexp = "[0-9a-zA-Z]{"+ Constant.CODE_LENGTH +"}")
@Documented
@Constraint(validatedBy = {})
@Target({ ElementType.FIELD,ElementType.PARAMETER})
@Retention(RUNTIME)
public @interface Code {
    String message() default "{code.pattern}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}
